import Vue from "vue";

import "normalize.css/normalize.css"; // A modern alternative to CSS resets

import ElementUI from "element-ui";
import "./styles/element-variables.scss";
// import 'element-ui/lib/theme-chalk/index.css'
// import locale from 'element-ui/lib/locale/lang/en' // lang i18n

import "@/styles/index.scss"; // global css

import App from "./App";
import store from "./store";
import router from "./router";

import "@/icons"; // icon
import "@/permission"; // permission control
import * as filters from "./filters";
/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
if (process.env.NODE_ENV === "production") {
  const { mockXHR } = require("../mock");
  mockXHR();
}

// set ElementUI lang to EN
Vue.use(ElementUI);
// 如果想要中文版 element-ui，按如下方式声明
// Vue.use(ElementUI)
// register global utility filters
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key]);
});
/*禁止回退*/
// import { banBackSpace } from "@/utils/banBackSpace";
// document.onkeydown = banBackSpace;

// 禁用浏览器前进后退
window.history.pushState(null, null, window.location.href);
window.addEventListener("popstate", function() {
  window.history.forward(-1);
  window.history.pushState(null, null, window.location.href);
});

//动态注册全局组件,将需要注册的组件名添加至components数组中,之后将这段单独开辟js文件存放
const components = [
  "cForm",
  "cpagination",
  "CrudTable",
  "ctable",
  "csearchbox"
];
for (let i = 0; i < components.length; i++) {
  const name = components[i];
  const component = require("@/components/" + name);
  Vue.component(name, component.default);
}

import "@/utils/directives.js"; //对话框可拖拽
// 计算tableHeight
// import tableHeight from '@/utils/tableHeight.js' // 引入
// Vue.use(tableHeight) // 添加
import "@/utils/timeProcessing"; // 时间处理过滤器
//时间格式
import dayjs from "dayjs";
Vue.prototype.$dayjs = dayjs;

Vue.config.productionTip = false;

new Vue({
  el: "#app",
  router,
  store,
  render: h => h(App)
});
